// 云函数入口文件
const cloud = require('wx-server-sdk')
// const rp = require('request')
const rp = require('request-promise')

// cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV }) // 使用当前云环境
cloud.init({ env: 'radar-server-cloud-3d2qcee2c1b04' })

// 云函数入口函数
exports.main = async (event, context) => {
  const wxContext = cloud.getWXContext()
  const aid = wxContext.APPID
  const asct = '521acf00dd4200218796b6edd4e3df13'
  try {
    const result = await rp({
      url: `https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=${aid}&secret=${asct}`,
      method: 'GET',
    })
    return result
  } catch (err) {
    return err
  }
}